package com.cxx.purchasecharge.dal;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DaoContext
{
    private static ApplicationContext applicationContext;
    private static UserDao userDao;
    private static RoleDao roleDao;
    private static AuthorityDao authorityDao;
    private static AccountingDao accountingDao;
    private static AccountingTypeDao accountingTypeDao;
    private static ContactDao contactDao;
    private static CustomerDao customerDao;
    private static GoodsDao goodsDao;
    private static GoodsDepositoryDao goodsDepositoryDao;
    private static GoodsStorageDao goodsStorageDao;
    private static GoodsTypeDao goodsTypeDao;
    private static GoodsUnitDao goodsUnitDao;
    private static OrderDao orderDao;
    private static OrderItemDao orderItemDao;
    private static PaymentAccountDao paymentAccountDao;
    private static PaymentDao paymentDao;

    static
    {
        applicationContext = new ClassPathXmlApplicationContext ("classpath:META-INF/spring/purchase-charge-dao-test.xml");
    }

    public static UserDao getUserDao ()
    {
        if (null == userDao)
        {
            userDao = applicationContext.getBean (UserDao.class);
        }
        return userDao;
    }

    public static RoleDao getRoleDao ()
    {
        if (null == roleDao)
        {
            roleDao = applicationContext.getBean (RoleDao.class);
        }
        return roleDao;
    }

    public static AuthorityDao getAuthorityDao ()
    {
        if (null == authorityDao)
        {
            authorityDao = applicationContext.getBean (AuthorityDao.class);
        }
        return authorityDao;
    }

    public static AccountingDao getAccountingDao ()
    {
        if (null == accountingDao)
        {
            accountingDao = applicationContext.getBean (AccountingDao.class);
        }
        return accountingDao;
    }

    public static AccountingTypeDao getAccountingTypeDao ()
    {
        if (null == accountingTypeDao)
        {
            accountingTypeDao = applicationContext.getBean (AccountingTypeDao.class);
        }
        return accountingTypeDao;
    }

    public static ContactDao getContactDao ()
    {
        if (null == contactDao)
        {
            contactDao = applicationContext.getBean (ContactDao.class);
        }
        return contactDao;
    }

    public static CustomerDao getCustomerDao ()
    {
        if (null == customerDao)
        {
            customerDao = applicationContext.getBean (CustomerDao.class);
        }
        return customerDao;
    }

    public static GoodsDao getGoodsDao ()
    {
        if (null == goodsDao)
        {
            goodsDao = applicationContext.getBean (GoodsDao.class);
        }
        return goodsDao;
    }

    public static GoodsDepositoryDao getGoodsDepositoryDao ()
    {
        if (null == goodsDepositoryDao)
        {
            goodsDepositoryDao = applicationContext.getBean (GoodsDepositoryDao.class);
        }
        return goodsDepositoryDao;
    }

    public static GoodsStorageDao getGoodsStorageDao ()
    {
        if (null == goodsStorageDao)
        {
            goodsStorageDao = applicationContext.getBean (GoodsStorageDao.class);
        }
        return goodsStorageDao;
    }

    public static GoodsTypeDao getGoodsTypeDao ()
    {
        if (null == goodsTypeDao)
        {
            goodsTypeDao = applicationContext.getBean (GoodsTypeDao.class);
        }
        return goodsTypeDao;
    }

    public static GoodsUnitDao getGoodsUnitDao ()
    {
        if (null == goodsUnitDao)
        {
            goodsUnitDao = applicationContext.getBean (GoodsUnitDao.class);
        }
        return goodsUnitDao;
    }

    public static OrderDao getOrderDao ()
    {
        if (null == orderDao)
        {
            orderDao = applicationContext.getBean (OrderDao.class);
        }
        return orderDao;
    }

    public static OrderItemDao getOrderItemDao ()
    {
        if (null == orderItemDao)
        {
            orderItemDao = applicationContext.getBean (OrderItemDao.class);
        }
        return orderItemDao;
    }

    public static PaymentAccountDao getPaymentAccountDao ()
    {
        if (null == paymentAccountDao)
        {
            paymentAccountDao = applicationContext.getBean (PaymentAccountDao.class);
        }
        return paymentAccountDao;
    }

    public static PaymentDao getPaymentDao ()
    {
        if (null == paymentDao)
        {
            paymentDao = applicationContext.getBean (PaymentDao.class);
        }
        return paymentDao;
    }

}
